package controller;

/**
 * Created by matth_000 on 1/15/2015.
 */


import view.*;
import model.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TheController {

    private TheFrame theView = new TheFrame();

    private TheModel theModel = new TheModel();


    public TheController(final TheFrame theFrame, final TheModel theData) {
        this.theView = theFrame;

        this.theModel = theData;


        this.theView.addCalculateListener(new CalculateListener());
    }

    class CalculateListener implements ActionListener{

        public void actionPerformed(ActionEvent e) {

            int firstNumber, secondNumber = 0;

            // Surround interactions with the view with
            // a try block in case numbers weren't
            // properly entered

            try{

                firstNumber = theView.getFirstNumber();
                secondNumber = theView.getSecondNumber();

                theModel.addTwoNumbers(firstNumber, secondNumber);

                theView.setCalcSolution(theModel.getCalculationValue());

            }

            catch(NumberFormatException ex){

                System.out.println(ex);

                theView.displayErrorMessage("You Need to Enter 2 Integers");

            }

        }

    }



}